package fty.baymax.experiment.atomic;

import fty.baymax.experiment.support.ThreadExecutor;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @Author: 710524
 * @Date: 2020-10-23 15:19
 * @Description: TODO
 */
public class AtomicIntergerAtomicity extends Thread{

    private static AtomicInteger number = new AtomicInteger(0);

    public AtomicIntergerAtomicity(String name) {
        super(name);
    }

    public AtomicIntergerAtomicity() {
    }

    public void increase() {
        int v = number.getAndIncrement();
        System.out.println(Thread.currentThread().getName() +"=="+ v);
    }

    @Override
    public void run() {
        for (int j = 0; j < 1000; j++) {
            increase();
        }
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ThreadExecutor executor = new ThreadExecutor(50);
        executor.wait(executor.submit(new AtomicIntergerAtomicity(), 50));
        System.out.println(number);
        executor.shutdownNow();
    }
}
